POV-Ray : Newsgroups : povray.newusers : help with macro : Re: help with macro Server Time
29 Jul 2024 06:14:23 EDT (-0400)
  Re: help with macro  
From: mine
Date: 15 May 2006 12:35:01
Message: <web.4468ad3d4767bb90a533cc200@news.povray.org>
"Chris B" <c_b### [at] btconnectcomnospam> wrote:
> "mine" <nomail@nomail> wrote in message
> news:web.44687a797f9206dfa533cc200@news.povray.org...
> > I've made a basic macro (with the help of a tutorial)that randomly places
> > objects (in this case spheres) in a given space. The trouble is the
> > tutorial didn't tell me how to stop the spheres from touching. Can anyone
> > help? I've included the macro below.
> >
> > #declare floater = sphere{<0,.5,0>, 1}
> > #declare thingy_red = <1,0,0>;
> > #declare floater_count = 20;
> > #declare Locations = seed(1);
> > #while (floater_count > 0)
> >  #declare x_loc = rand(Locations)*7-1;
> >  #declare y_loc = rand(Locations)*7-1;
> >  #declare z_loc = rand(Locations)*7-1;
> > object{floater
> >      pigment{color thingy_red}
> >      translate <x_loc,y_loc,z_loc>
> >      }
> >  #declare floater_count = floater_count - 1;
> > #end
> >
> >
>
> Hi,
>
> You can declare an array of size 'floater_count', then each time round the
> current loop, do another loop to test whether the position of the centre of
> the sphere is closer than the diameter of floater to any of the existing
> positions (see the vlength() function, which you can use on the difference
> between each pair of positions).
>
> Then you can put the 'object' statement plus the line where you decrement
> 'floater_count' inside an #if clause along with a new line to add the new
> position into the array.
>
> If you're likely to want to increase float_count to where you get close to
> the limit where you can't find enough positions, then you should also add a
> way of breaking out of your existing loop to avoid that you loop
> indefinitely.
>
> I didn't post code because it sounds like you're trying to work stuff out
> for yourself, but if you want the answer, just say.
>
> Regards,
> Chris B.

hi Chris B.
I tried figure it out but kept on getting lost. You better just give me the
answer. I sort of understand what I was trying to do but I have no idea how
to do it. Thanks for helping.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.